package com.ruoyi.business.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.business.common.Result;
import com.ruoyi.business.entity.RoomType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.business.service.FrontRoomTypeService;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Ao
 * @since 2024-01-08
 */
@RestController
@RequestMapping("business/roomType")
public class FrontRoomTypeController {

    @Autowired
    private FrontRoomTypeService frontRoomTypeService;


    @RequestMapping("/list")
    public Result<List<RoomType>> getList(){
        List<RoomType> list = frontRoomTypeService.list();
         return Result.success(list);

    }

    @RequestMapping("/add")
    public Result<String> add(@RequestBody RoomType roomType){
        LambdaQueryWrapper<RoomType> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RoomType::getRoomTypeName,roomType.getRoomTypeName());
        List<RoomType> list = frontRoomTypeService.list(queryWrapper);
        if(list.size()>0){
            return Result.error("类型已存在");
        }

        boolean save = frontRoomTypeService.save(roomType);
        if(!save){

            return Result.error("添加失败");
        }
        return Result.success("添加成功");

    }





}

